package com.itcast.donkey.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.itcast.donkey.R;
import com.itcast.donkey.adapters.VPLoginAdapter;
import com.itcast.donkey.fragments.LoginFragment;
import com.itcast.donkey.fragments.RegisterFragment;

import java.util.ArrayList;

/**
 * Created by lanouhn on 16/8/26.
 */
public class LoginActivity extends AppCompatActivity {
    private ImageView iv_chan_scenic_spot;
    private ViewPager vpLogin;
    private TabLayout tabLogin;
    private LoginFragment login;
    private RegisterFragment regist;
    private VPLoginAdapter adapter;
    private ArrayList<String> tabNames = new ArrayList<String>();
    private ArrayList<Fragment> lists = new ArrayList<Fragment>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_regist);
        initView();
        initData();
        initEnent();
    }

    private void initView() {
        vpLogin = (ViewPager) findViewById(R.id.viewPager);
        tabLogin = (TabLayout) findViewById(R.id.tabs);
        iv_chan_scenic_spot = (ImageView) findViewById(R.id.iv_chan_scenic_spot);
    }

    private void initData() {
        login = new LoginFragment();
        regist = new RegisterFragment();
        lists.add(login);
        lists.add(regist);
        tabNames.add("登录");
        tabNames.add("注册");
        adapter = new VPLoginAdapter(getSupportFragmentManager(), tabNames, lists);
        vpLogin.setAdapter(adapter);
        tabLogin.setupWithViewPager(vpLogin);
    }

    private void initEnent() {
        iv_chan_scenic_spot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

}
